<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <!--    <link href="/static/css/dialog.css" rel="stylesheet"/>-->
    <!--    <script src="/static/js/dialog.js"></script>-->
    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--引用layui弹框插件-->
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!-- PNotify -->
    <script type="text/javascript" src="/static/pnotify/pnotify.js"></script>
    <link href="/static/pnotify/pnotify.css" rel="stylesheet" type="text/css"/>
    <link href="/static/pnotify/pnotify.brighttheme.css" rel="stylesheet" type="text/css"/>


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>
<style>
    .modal-body {
        background-color: #fff !important;
    }
</style>


<div class="config_content newtest">

    <div class="container new_serach">
        {volist name="powerList" id="vo"}
        <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
        {/volist}
    </div>

    <div class="modal-body ">

        <table class="layui-hide" id="demo" lay-filter="demo"></table>
        <script type="text/html" id="barDemo">
            <button class="btn-sm btn-primary" lay-event="edit" >编辑</button>
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a class="layui-btn layui-btn-sm" lay-event="add">添加</a>
            </div>
        </script>
    </div>
</div>


<script>
    var newModal = new yii.modal();
    layui.use(['form', 'jquery', 'layer', 'laydate','table'], function () { //独立版的layer无需执行这一句
        var table = layui.table //表格

        table.render({
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            elem: '#demo', // 表格id
            url:"{:URL('admin/system/attribute')}",
            where:{type:'list'},
            title: '单元列表',
            page: true, // 树形表格一般是没有分页的
            cols: [[
                {field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80}
                ,{field: 'name', title: '名称'}
                ,{field: 'key', title: 'KEY'}
                ,{field: 'value', title: '值'}
                ,{fixed: 'right',title: '操作', width:200, align:'center', toolbar: '#barDemo'}
            ]],
            done: function() {
                layer.closeAll('loading');
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj){
            switch(obj.event){
                case 'edit':
                    var id = obj.data.id;
                    newModal.initialization({
                        url: "{:URL('admin/System/addAttribute')}",
                        type: "post",
                        data:{
                            type:'detail',
                            id:id
                        }
                    });
                    break;
            };
        });

        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    newModal.initialization({
                        url: "{:URL('admin/System/addAttribute')}",
                        type: "post",
                        data:{
                            type:'detail'
                        }
                    });
                    break;

            };
        });

    });



    //统一modal执行保存action
    newModal.on("add",function(data){
        var data=$(newModal.getid()).find("form").serialize();
        newModal.remoteajax({
            url: "{:URL('admin/System/addAttribute')}",
            type: "post",
            data:data
        });
    });



</script>
</body>
</html>
